using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using WPFExcelReport.Helpers;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VICC_WFEVENTS
    {
        public void SetUpNewRow(ref DataRow dwReturn)
        {

            switch (app.company)
            {
                case "YGR":
                case "YCC":
                default:
                    #region=========
                    dwReturn["MANDANT"] = app.Mandant;
                    dwReturn["ROWNID"] = INTEXDBC.GetSeq();
                    dwReturn["CONTROL"] = "NO ";
                    dwReturn["USERGROUP"] = "";
                    dwReturn["WFEUSER"] = app.User;
                    dwReturn["WFEVENTS"] = "                    ";
                    dwReturn["WFEHANDLER"] = "                    ";
                    dwReturn["WFSOURCE"] = "                                                                                                                                                                                                        ";
                    dwReturn["WFWHEN"] = "                ";
                    dwReturn["WHAT"] = "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ";
                    dwReturn["HOW"] = "                    ";
                    dwReturn["ORDTYPE"] = "  ";
                    dwReturn["KRS"] = "  ";
                    dwReturn["LFD"] = "      ";
                    dwReturn["POS"] = "   ";
                    dwReturn["ARTTYPE"] = " ";
                    dwReturn["ARTICLE"] = "                    ";
                    dwReturn["ARTDES"] = "                                        ";
                    dwReturn["VAR"] = "   ";
                    dwReturn["COLOR"] = "          ";
                    dwReturn["CDES"] = "                                        ";
                    dwReturn["ASIZE"] = "       ";
                    dwReturn["FINISH"] = "          ";
                    dwReturn["FINDES"] = "                                        ";
                    dwReturn["P1"] = "                                        ";
                    dwReturn["P2"] = "                                        ";
                    dwReturn["P3"] = "                                        ";
                    dwReturn["P4"] = "                                        ";
                    dwReturn["P5"] = "                                        ";
                    dwReturn["P6"] = "                                        ";
                    dwReturn["NEWUSER"] = "        ";
                    dwReturn["NEWTIME"] = "                ";
                    dwReturn["CHGUSER"] = "        ";
                    dwReturn["CHGTIME"] = "                    ";
                    #endregion
                    break;
            }
        }
        public void InsertICC_WFEVENTS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            dwData["NEWUSER"] = app.User;
            dwData["NEWTIME"] = date;
            or1 = OracleDB.CreateCommand();

            or1.CommandText = "INSERT INTO ICC_WFEVENTS(MANDANT,ROWNID,USERGROUP,WFEUSER,WFEVENTS,WFEHANDLER,WFSOURCE,WHAT,HOW,ORDTYPE,KRS,LFD,POS,ARTTYPE,ARTICLE,COLOR,P1,NEWUSER,NEWTIME)"
                        + " VALUES (:MANDANT:,:ROWNID:,:USERGROUP:,:WFEUSER:,:WFEVENTS:,:WFEHANDLER:,:WFSOURCE:,:WHAT:,:HOW:,:ORDTYPE:,:KRS:,:LFD:,:POS:,:ARTTYPE:,:ARTICLE:,:COLOR:,:P1:,:NEWUSER:,:NEWTIME:)";

            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);
        }

        public DataSet QueryICC_WFEVENTS(DataRow dwData, int option = 1)
        {

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1: SResult = QWF01(dwData); break;
                case 2:
                    or1.CommandText = "SELECT * FROM ICC_WFEVENTS WHERE"
                    + " MANDANT=:MANDANT: AND (WFEUSER LIKE '" + dwData["WFEUSER"].ToString().Trim() + "%'"
                    + " OR WFSOURCE LIKE  '" + dwData["WFSOURCE"].ToString().Trim() + "%'"
                    + " ) AND WFEVENTS LIKE  '" + dwData["WFEVENTS"].ToString().Trim() + "%'"
                    + " AND CONTROL LIKE  '" + dwData["CONTROL"].ToString().Trim() + "%'"
                    + " AND KRS LIKE  '" + dwData["KRS"].ToString().Trim() + "%'"
                    + " AND LFD LIKE  '" + dwData["LFD"].ToString().Trim() + "%'";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    SResult = Connect2Proxy(or1);
                    break;
                case 3:
                    or1.CommandText = "SELECT * FROM ICC_WFEVENTS WHERE  MANDANT=:MANDANT: AND WFEVENTS=:WFEVENTS: AND ARTICLE=:ARTICLE: AND COLOR=:COLOR: "; ;
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    SResult = Connect2Proxy(or1);
                    break;
                case 4:
                    or1.CommandText = "SELECT * FROM ICC_WFEVENTS WHERE  MANDANT=:MANDANT: AND KRS=:KRS: AND LFD=:LFD:"; ;
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    SResult = Connect2Proxy(or1);
                    break;
                case 5: SResult = QWF05(dwData); break;
                case 99:
                    or1.CommandText = "SELECT * FROM ICC_WFEVENTS WHERE  MANDANT=:MANDANT: AND WFEVENTS=:WFEVENTS: AND ORDTYPE=:ORDTYPE: AND KRS=:KRS: AND LFD=:LFD: AND ARTTYPE=:ARTTYPE: AND ARTICLE=:ARTICLE: AND COLOR=:COLOR: "; ;
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    SResult = Connect2Proxy(or1);
                    break;
                default:
                case 9999:
                    or1.CommandText = "SELECT * FROM ICC_WFEVENTS";
                    SResult = Connect2Proxy(or1);
                    break;
            }
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QWF01(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM ICC_WFEVENTS WHERE  ROWNID=:ROWNID:"; ;
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;

            return SResult;
        }
        public DataSet QWF05(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM ICC_WFEVENTS WHERE  MANDANT=:MANDANT: AND WFEVENTS=:WFEVENTS: AND CONTROL=:CONTROL: AND WFEUSER=:WFEUSER:"; ;
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;

            return SResult;
        }
        public DataSet QWF0501(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT ROWNID, WFEVENTS,WFEHANDLER,WHAT,ORDTYPE,KRS,LFD,POS,ARTTYPE,ARTICLE,COLOR,P1,NEWUSER,NEWTIME "
                + " FROM ICC_WFEVENTS P WHERE  MANDANT=:MANDANT:  AND CONTROL=:CONTROL: AND WFEUSER=:WFEUSER:"
            + " ORDER BY P.ROWNID DESC";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;

            return SResult;
        }
        public DataSet QWF06(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT P.*,NEXTEVENTS1,DEFCONTROL1,NEXTEVENTS2,DEFCONTROL2,NEXTEVENTS3,DEFCONTROL3 FROM ICC_WFEVENTS P"
                + " JOIN ICC_WFEVENTDEF X ON  X.MANDANT=P.MANDANT AND  RTRIM(P.WFEVENTS)=RTRIM(X.WFEVENTS)"
                + " WHERE  P.MANDANT=:MANDANT: AND P.KRS=:KRS: AND P.LFD=:LFD: AND P.POS=:POS: "
                + dwData["WFEVENTS"].ToString()
                + dwData["CONTROL"].ToString()
                + " ORDER BY P.ROWNID DESC";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;

            return SResult;
        }
        public DataSet QWFAPP00(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT P.CONTROL FROM ICC_WFEVENTS P"
                 + " WHERE  P.MANDANT=:MANDANT: AND P.KRS=:KRS: AND P.LFD=:LFD: AND P.POS=:POS: AND WFEVENTS=:WFEVENTS: "
                + " ORDER BY P.ROWNID DESC";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QWFEVENTS(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT P.* FROM ICC_WFEVENTS P"
                 + " WHERE  P.MANDANT=:MANDANT: AND P.KRS=:KRS: AND P.LFD=:LFD: AND P.POS=:POS: AND WFEVENTS=:WFEVENTS: AND CONTROL=:CONTROL: "
                + " ORDER BY P.ROWNID DESC";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QueryICC_WFEVENTS(string wfid, int option = 1)
        {
            return LOADBYID(wfid);
        }
        public void DeleteICC_WFEVENTS(DataRow dwData, int option = 1)
        {
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ICC_WFEVENTS WHERE  ROWNID=:ROWNID:"; ;
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 2:
                    or1.CommandText = "DELETE FROM ICC_WFEVENTS WHERE  WHAT=:WHAT:"; ;
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
            }
            Connect2Proxy(or1);
        }
        public void UpdateICC_WFEVENTS(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {

            if (option == 0)
            {
                switch (app.company)
                {
                    default:
                        option = 1;
                        break;
                }
            }
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==
                    or1.CommandText = "UPDATE ICC_WFEVENTS SET "
                            + "MANDANT=:MANDANT:,"
                            + "CONTROL=:CONTROL:,"
                            + "USERGROUP=:USERGROUP:,"
                            + "WFEUSER=:WFEUSER:,"
                            + "WFEVENTS=:WFEVENTS:,"
                            + "WFEHANDLER=:WFEHANDLER:,"
                            + "WFSOURCE=:WFSOURCE:,"
                            + "WFWHEN=:WFWHEN:,"
                            + "WHAT=:WHAT:,"
                            + "HOW=:HOW:,"
                            + "ORDTYPE=:ORDTYPE:,"
                            + "KRS=:KRS:,"
                            + "LFD=:LFD:,"
                            + "POS=:POS:,"
                            + "ARTTYPE=:ARTTYPE:,"
                            + "ARTICLE=:ARTICLE:,"
                            + "ARTDES=:ARTDES:,"
                            + "VAR=:VAR:,"
                            + "COLOR=:COLOR:,"
                            + "CDES=:CDES:,"
                            + "ASIZE=:ASIZE:,"
                            + "FINISH=:FINISH:,"
                            + "FINDES=:FINDES:,"
                            + "P1=:P1:,"
                            + "P2=:P2:,"
                            + "P3=:P3:,"
                            + "P4=:P4:,"
                            + "P5=:P5:,"
                            + "P6=:P6:,"
                            + "NEWUSER=:NEWUSER:,"
                            + "NEWTIME=:NEWTIME:,"
                            + "CHGUSER=:CHGUSER:,"
                            + "CHGTIME=:CHGTIME: "
                        + " WHERE  "
                        + "    ROWNID=:ROWNID: ";
                    #endregion
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
            }

            Connect2Proxy(or1);
        }
        public void UWF02(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE ICC_WFEVENTS SET WHAT=:WHAT: WHERE  ROWNID=:ROWNID:"; ;
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);
        }
    }
}
